package com.xiaoma.tpo.dao;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.UserKey;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Owner on 2015/5/12.
 */
@Repository
public class UserKeyDao extends BaseDaoImpl<UserKey> {
    public List<UserKey> getMyKeys(int userid,int currentPage ,int pageSize){
        String sql = "select * from user_key where user_id=? limit ?,?";

        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(UserKey.class, getNameHandler()),userid,(currentPage-1)*pageSize,pageSize);

        return (List<UserKey>) list;
    }
    
    public List<UserKey> getLasted(int userId){
        String sql = "select * from user_key where user_id=? order by id desc limit 1";

        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(UserKey.class, getNameHandler()),userId);

        return (List<UserKey>) list;
    }
    
}
